package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.DeptBean;
import com.project.bean.EmployeeBean;
import com.project.mapper.IDeptMapper;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Title: DeptServiceImpl
 * @Package: com.project.service.impl
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/7/15 - 15:12
 */
@SuppressWarnings("all")
@Service
@Transactional
public class DeptServiceImpl implements IDeptService {
    @Autowired
    private IDeptMapper deptMapper;
    @Autowired
    private IEmployeeMapper employeeMapper;

    @Override
    public List<DeptBean> findAll() {
        return deptMapper.findAll();
    }

    @Override
    public void add(DeptBean deptBean, List<EmployeeBean> employeeBeanList) {
        deptMapper.insert(deptBean);
        employeeMapper.addMore(deptBean.getId(), employeeBeanList);

    }

    @Override
    public void delCasede(Integer id) {
        deptMapper.delCasede(id);
    }

    @Override
    public void delSetNull(Integer id) {
        deptMapper.delSetNull(id);
    }

    @Override
    public DeptBean findById(Integer id) {
        DeptBean deptBean = deptMapper.selectById(id);
        QueryWrapper<EmployeeBean> qw = new QueryWrapper<>();
        qw.eq("fk_deptId", id);
        deptBean.setEmployeeBeanList(employeeMapper.selectList(qw));
        return deptBean;
    }
}
